package pathfinder;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Block
{
    private Point loc;
    public int size;
    private int type;
    
    Block(Point topLeftCorner, int type)
    {
        this.type = type;
        loc = topLeftCorner.clone();
        checkType();
    }
    Block(java.awt.Point topLeftCorner, int type)
    {
        this.type = type;
        loc = new Point(topLeftCorner);
        checkType();
    }
    public int getSize()
    {
        return 250-50*type;
    }
    private void checkType()
    {
        if(type < 1 || type > 3)
        {
            System.out.println("Error. Block created with illegal type.");
        }
        size = getSize();
    }
    public Point getLoc()
    {
        return loc;
    }
    public int getType()
    {
        return type;
    }
    public Point getTL()
    {
        return loc;
    }
    public Point getTR()
    {
        return new Point(loc.x + 250 - (50*type), loc.y);
    }
    public Point getBR()
    {
        return new Point(loc.x + 250 - (50*type), loc.y + 250 - (50*type));
    }
    public Point getBL()
    {
        return new Point(loc.x, loc.y + 250 - (50*type));
    }
    
    public void draw(Graphics g)
    {
        g.setColor(Color.lightGray);
        g.fillRect((int)loc.x, (int)loc.y, getSize(), getSize());
    }
    
    public static void SortBlocks(ArrayList<Block> blocks)
    {
        Collections.sort(blocks,new Comparator<Block>()
        {
            @Override
            public int compare(Block block1, Block block2)
            {
                return (int)(block1.loc.x - block2.loc.x);
            }
        });
    }
}
